#include "Common.h"
#include "Resource.h"
#include "String.h"
#include "Character.h"
#include "WSSocket.h"
#include "AIScript.h"
#include "AIInterface.h"



namespace AIScript {
	
	MissionAIScript::MissionAIScript( Resource * pUnit ) :AIScript(pUnit)
	{
		m_type = AITYPE_MISSION;

	}
	
	
	EffectAIScript::EffectAIScript(Resource * pEffect):AIScript(pEffect)
	{
		m_type = AITYPE_EFFECT;
	}
	
	bool EffectAIScript::CountNumber(CharPtr &pChr, const uint32 addNum)
	{
		if(pChr.isNull())
			return false;
		Effect * pEffect = (Effect*)m_Unit;
		uint32 count = pEffect->getUInt32Field("data1") + addNum;
		uint32 max = pEffect->model->getUInt32Field("effect1");
		if (count < max)
		{
			pEffect->setUInt32Field("data1", count);
			// pEffect->SaveDB();
			return false;
		}
		else
		{
			pEffect->setUInt32Field("data1", max);
		}
		return true;
	}
	
	void EffectAIScript::CountFinishNum()
	{
		Effect * pEffect = (Effect*)m_Unit;
		EffectModelPtr pEMPtr = pEffect->model;
		if (pEMPtr.isNull())
			return;
		{
			WGS_EFCOUNT_INNER_LOCK
			pEMPtr->setUInt32Field("effect9", pEMPtr->getUInt32Field("effect9") + 1);
		}
		pEMPtr->SaveDB();
	}
	
	TownAIScript::TownAIScript(Resource * pUnit):AIScript(pUnit)
	{
		m_type = AITYPE_CITY;
	}
}
